#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Library.Services;
using System.Collections;
using Library.Entity;

#endregion

namespace Library
{
    public partial class FormFindMember : Form
    {
        MemberService m_MemberService = new MemberService();
        Member m_member = null;
        private IFindMember formBookStockAdjustment;
        public FormFindMember()
        {
            InitializeComponent();
            initColumn();
            textBoxKeyword.Focus();
        }

        public FormFindMember(IFindMember formBookStockAdjustment)
            : this()
        {
            // TODO: Complete member initialization
            this.formBookStockAdjustment = formBookStockAdjustment;
        }
        private void initColumn()
        {
            listView.Columns.Add("Code", 75, HorizontalAlignment.Left);
            listView.Columns.Add("Name", 150, HorizontalAlignment.Left);
        }

        private void buttonFInd_Click(object sender, EventArgs e)
        {
            listView.Items.Clear();
            IList result = m_MemberService.GetMemeberByLike(textBoxKeyword.Text);
            foreach (Member b in result) 
            {
                ListViewItem item = listView.Items.Add(b.Code);
                item.SubItems.Add(b.Name);
                item.Tag = b;
            }
            if (result.Count == 1)
            {
                listView.Focus();
                listView.Items[0].Selected = true;
            }
        }

        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            if (listView.SelectedItem != null)
            {
                m_member = (Member)listView.SelectedItem.Tag;
                formBookStockAdjustment.SetMember(m_member);
                this.Close();
            }
        }

        public Member Member
        {
            get { return m_member; }
        }

        private void listView_KeyDown(object objSender, KeyEventArgs objArgs)
        {
            if (objArgs.KeyData == Keys.Enter)
            {
                listView1_DoubleClick(null, null);
            }
        }

        private void textBoxKeyword_EnterKeyDown(object objSender, KeyEventArgs objArgs)
        {
            buttonFInd_Click(objSender, objArgs);
        }
    }
}